package com.hopu.mybatis02.service.impl;

import com.hopu.mybatis02.mapper.BookMapper;
import com.hopu.mybatis02.mapper.ChapterMapper;
import com.hopu.mybatis02.pojo.BookExt;
import com.hopu.mybatis02.pojo.Chapter;
import com.hopu.mybatis02.service.IBookService;
import jakarta.annotation.Resource;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class BookServiceImpl implements IBookService {

    @Resource
    private BookMapper bookMapper;
    @Resource
    private ChapterMapper chapterMapper;

    @Override
    public List<BookExt> getBookList(List<String> category) {
        return bookMapper.selectBookList(category);
    }

    @Override
    public BookExt getBookDetailbyId(long bookId) {
        //根据id查询book表章节信息
        BookExt bookExt = bookMapper.selectBookDetailbyId(bookId);
        //根据书籍id查询章节列表
        List<Chapter> chapters = chapterMapper.selectChapterListByBookId(bookId);
        //把章节列表塞进去
        bookExt.setBookChapters(chapters);
        return bookExt;
    }
}
